package com.lc.advertising.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.advertising.R;
import com.lc.advertising.app.AppActivity;
import com.lc.advertising.http.glide.GlideApp;
import com.lc.advertising.http.request.PersonalApi;
import com.lc.advertising.http.response.PersonalBean;
import com.lc.advertising.other.IntentKey;
import com.lc.advertising.util.CourseUtils;
import com.lc.advertising.util.SPUtil;
import com.lc.advertising.util.SettingBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PeopleCenterActivity extends AppActivity {
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_cart_num)
    TextView tvCartNum;
    @BindView(R.id.tv_order_num)
    TextView tvOrderNum;
    @BindView(R.id.my_pic)
    ImageView myPic;
    @BindView(R.id.sb_renzheng)
    SettingBar sbRenzheng;
    private String nickname;
    private String mobile;
    private String dheadimg;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_peoplecenter;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (CourseUtils.isNotNullOrEmpty(SPUtil.get(this, IntentKey.UID, ""))) {
            personal();
            tvPhone.setVisibility(View.VISIBLE);
            tvName.setVisibility(View.VISIBLE);
        }

    }

    private void personal() {
        EasyHttp.post(this)
                .api(new PersonalApi()
                        .setUid(SPUtil.get(this, IntentKey.UID, "")))

                .request(new HttpCallback<PersonalBean>(this) {


                    @Override
                    public void onSucceed(PersonalBean data) {
//
                        if (data.getCode() == 200) {
                            if (data.getMember().getIs_renzheng().equals("1")) {
sbRenzheng.setRightText("审核中");
                            }else {
                                sbRenzheng.setRightText("审核通过");
                            }

                            tvCartNum.setText(data.getMember().getCar_number());
                            nickname = data.getMember().getNickname();
                            mobile = data.getMember().getMobile();
                            dheadimg = data.getMember().getDheadimg();
                            tvName.setText(data.getMember().getNickname());
                            tvPhone.setText(data.getMember().getMobile());
                            GlideApp.with(getActivity())
                                    .load(data.getMember().getDheadimg())
                                    .placeholder(R.mipmap.mine_default_avatar)
                                    .error(R.mipmap.mine_default_avatar)
                                    .transform(new MultiTransformation<>(new CenterCrop(), new CircleCrop()))
                                    .into(myPic);
                        }
                    }


                });
    }

    @OnClick({R.id.image_back, R.id.my_pic, R.id.tv_login, R.id.tv_name, R.id.tv_look, R.id.sb_renzheng, R.id.sb_tuiguang, R.id.sb_qianbao, R.id.sb_setting,R.id.sb_message})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.image_back:
                finish();
                break;
            case R.id.my_pic:
            case R.id.tv_name:
                startActivity(new Intent(this,PeopleDataActivity.class).putExtra("nickname",nickname).putExtra("mobile",mobile).putExtra("dheadimg",dheadimg));
                break;
            case R.id.tv_login:
                break;
            case R.id.tv_look:
                startActivity(OrderActivity.class);

                break;
            case R.id.sb_renzheng:
                startActivity(AttestationActivity.class);

                break;
            case R.id.sb_tuiguang:
                startActivity(SpreadActivity.class);

                break;
            case R.id.sb_qianbao:
                startActivity(WalletActivity.class);

                break;
            case R.id.sb_setting:
                startActivity(SettingActivity.class);

                break;
            case R.id.sb_message:
                startActivity(MessageActivity.class);

                break;

        }
    }
}
